package shapes;

/**
 * <p>Title: Project 12 - Shape class</p>
 * <p>Description: CS 235 Project #12
 *       Used for looking at preconditions, postconditions, asserts, javadoc.</p>
 * @author Anthony Varghese
 * @date   February 5th 2012
 * @version 1.0
 */

public abstract class Shape extends java.awt.Component {
	/**
	 * Data member serialVersionUID - gets rid of the warning
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * abstract method draw
	 */
	public abstract void draw(java.awt.Graphics g);
	
	/**
	 * abstract method update - calls the appropriate draw method
	 */
	public void update(java.awt.Graphics g) {
		draw(g);
	}	
}

class Rectangle extends Shape {
	/**
	 * Data members - the coordinates of the two points that define a line segment
	 */
	private static final long serialVersionUID = 1L;
	private int[] coordinates;

	/**
	 * Constructor for Line
	 * params are the 6 ints that define the coordinates of the three vertices of a triangle.
	 * 
	 * @require 
	 * 
	 * @ensure
	 * 
	 */
	public Rectangle(int x1, int y1, int x2, int y2){
		coordinates = new int[4];
		coordinates[0] = x1;
		coordinates[1] = y1;
		coordinates[2] = x2;
		coordinates[3] = y2;
	}

	/**
	 * draw - the implementation of the abstract draw method
	 *        that will accomplish the drawing of a triangle.
	 * 
	 * @require 
	 * 
	 * @ensure
	 * 
	 */
	@Override
	public void draw(java.awt.Graphics g) {
		g.drawLine(coordinates[0], coordinates[1], coordinates[2], coordinates[1]);
		g.drawLine(coordinates[2], coordinates[1], coordinates[2], coordinates[3]);
		g.drawLine(coordinates[2], coordinates[3], coordinates[0], coordinates[3]);
		g.drawLine(coordinates[0], coordinates[3], coordinates[0], coordinates[1]);
	}
}

class Line extends Shape {
	/**
	 * Data members - the coordinates of the two points that define a line segment
	 */
	private static final long serialVersionUID = 1L;
	private int[] coordinates;

	/**
	 * Constructor for Line
	 * params are the 4 ints that define the coordinates of the two points.
	 * 
	 * @require 
	 * 
	 * @ensure
	 * 
	 */
	public Line(int x1, int y1, int x2, int y2){
		coordinates = new int[4];
		coordinates[0] = x1;
		coordinates[1] = y1;
		coordinates[2] = x2;
		coordinates[3] = y2;
	}

	/**
	 * draw - the implementation of the abstract draw method
	 *        that will accomplish the drawing of a line.
	 * 
	 * @require 
	 * 
	 * @ensure
	 * 
	 */
	@Override
	public void draw(java.awt.Graphics g) {
		g.drawLine(coordinates[0], coordinates[1], coordinates[2], coordinates[3]);
	}
}



class Triangle extends Shape {
	/**
	 * Data members - the coordinates of the two points that define a line segment
	 */
	private static final long serialVersionUID = 1L;
	private int[] coordinates;

	/**
	 * Constructor for Line
	 * params are the 6 ints that define the coordinates of the three vertices of a triangle.
	 * 
	 * @require 
	 * 
	 * @ensure
	 * 
	 */
	public Triangle(int x1, int y1, int x2, int y2, int x3, int y3){
		coordinates = new int[6];
		coordinates[0] = x1;
		coordinates[1] = y1;
		coordinates[2] = x2;
		coordinates[3] = y2;
		coordinates[4] = x3;
		coordinates[5] = y3;
	}

	/**
	 * draw - the implementation of the abstract draw method
	 *        that will accomplish the drawing of a triangle.
	 * 
	 * @require 
	 * 
	 * @ensure
	 * 
	 */
	@Override
	public void draw(java.awt.Graphics g) {
		g.drawLine(coordinates[0], coordinates[1], coordinates[2], coordinates[3]);
		g.drawLine(coordinates[2], coordinates[3], coordinates[4], coordinates[5]);
		g.drawLine(coordinates[4], coordinates[5], coordinates[0], coordinates[1]);
	}
}